<?php

namespace App\Observers;

use App\Http\Model\Log;

class BasicObserver
{
    protected $log = [];
    protected $user;

    public function __construct()
    {
        $this->log['username'] = auth()->user()->username ?? 'CLI';
        $this->log['ip'] = request()->ip() ?? '127.0.0.1';
        $this->log['time'] = date('Y-m-d H:i:s',time());
        $this->log['type'] = 1;  //日志类型0错误日志，1操作日志
        $this->user = auth()->user()->username ?? 'CLI';
    }

    public function logInfo()
    {
        Log::create($this->log);
    }
}
